package com.hua.yuan.ui.adapter;

import android.content.Context;
import android.view.LayoutInflater;
import android.view.View;
import android.view.ViewGroup;
import android.widget.BaseAdapter;
import android.widget.ImageView;
import android.widget.TextView;

import com.bumptech.glide.Glide;
import com.hua.yuan.R;
import com.hua.yuan.ui.module.FavoriteBean;

import java.util.List;

/**
 * Created by huangyang on 2018/6/23.
 * 收藏的adapter
 */

public class FavoriteAdapter extends BaseAdapter {

    private Context context;
    private List<FavoriteBean> list;

    public FavoriteAdapter(Context context) {
        this.context = context;
    }

    public List<FavoriteBean> getList() {
        return list;
    }

    public void setList(List<FavoriteBean> list) {
        this.list = list;
    }

    @Override
    public int getCount() {
        return list == null ? 0 : list.size();
    }

    @Override
    public Object getItem(int i) {
        return list == null ? null : list.get(i);
    }

    @Override
    public long getItemId(int i) {
        return list == null ? 0 : i;
    }

    @Override
    public View getView(int i, View view, ViewGroup viewGroup) {
        ViewHolder viewHolder;
        if (view == null){
            view = LayoutInflater.from(context).inflate(R.layout.favorite_item_view,null);
            viewHolder = new ViewHolder(view);
            view.setTag(viewHolder);
        }else {
            viewHolder = (ViewHolder) view.getTag();
        }

        viewHolder.bind(i);

        return view;
    }


    class ViewHolder {

        private ImageView favoriteImg;
        private TextView favoriteName;
        private TextView favoriteType;
        private TextView favoriteDis;
        private TextView favoriteCancel;

        ViewHolder(View view) {
            favoriteImg = view.findViewById(R.id.favoriteImg);
            favoriteName = view.findViewById(R.id.favoriteName);
            favoriteType = view.findViewById(R.id.favoriteType);
            favoriteDis = view.findViewById(R.id.favoriteDis);
            favoriteCancel = view.findViewById(R.id.favoriteCancel);
        }


        void bind(int i) {

            FavoriteBean bean = list.get(i);
            Glide.with(context).load(bean.getImageUrl()).into(favoriteImg);
            favoriteName.setText(bean.getName());
            favoriteType.setText(bean.getType());
            favoriteDis.setText(bean.getFavoriteDis());
            favoriteCancel.setOnClickListener(new View.OnClickListener() {
                @Override
                public void onClick(View view) {

                }
            });


        }
    }

}
